package io.renren.modules.api.controller;

import io.renren.common.utils.R;
import io.renren.common.validator.Assert;
import io.renren.modules.api.interceptor.AuthorizationInterceptor;
import io.renren.modules.feedback.entity.FeedbackinfosEntity;
import io.renren.modules.feedback.service.FeedbackinfosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: stf
 * @description: 反馈
 * @author: Custom
 * @create: 2018-11-01 18:08
 **/

@RestController
@RequestMapping("/api/feedback")
public class ApiFeedbackController {

    @Autowired
    private FeedbackinfosService feedbackinfosService;

    //提交反馈
    @PostMapping("/submit")
    public R submitFeedback(FeedbackinfosEntity feedbackinfosEntity,HttpServletRequest request){
        //必要字段验证
        Assert.isBlank(feedbackinfosEntity.getContexts(),"反馈内容不能为空！");
        Assert.isNull(feedbackinfosEntity.getFeedbacktype(),"反馈类型不能为空！");
        String userinfoid = (String) request.getAttribute(AuthorizationInterceptor.USER_KEY);
        feedbackinfosEntity.setFeedbackuser(userinfoid);

        //类型验证
        R typeError = feedbackinfosService.judgeFeedbackTypeError(feedbackinfosEntity);
        if(typeError != null){
            return typeError;
        }
        feedbackinfosService.submitFeedback(feedbackinfosEntity);
        return R.ok().put("msg","提交成功，我们将审查处理此事！");
    }

}
